﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Windows.Media.Imaging;
namespace INTEX.DataBase.CE
{
    public class MINTEXDB : DataContext
    {

        public static string ConnectionString = "Data Source=isostore:Data/PhoneDB/mintexdb.sdf";

        public static string FileName = "mintexdb.sdf";
        public Mapper DBMapper = null;
        // Pass the connection string to the base class.
        public MINTEXDB()
            : base("")
        { }

        public MINTEXDB(string connectionString)
            : base(connectionString)
        {
            ConnectionString = connectionString;
            DBMapper = new Mapper();
            DBMapper.DBStr = ConnectionString;
        }
        public void MergeDB(string conn)
        {
             MINTEXDB mtemp = new MINTEXDB(conn);
            try
            {               
                var qWPMENU = from m in mtemp.WPMENU select m;
                DBMapper.MapWPMENU(qWPMENU.ToList(), true);

                var qABAUFM = from m in mtemp.ABAUFM select m;
                DBMapper.MapABAUFM(qABAUFM.ToList(), true);
                var qABFOLGE = from m in mtemp.ABFOLGE select m;
                DBMapper.MapABFOLGE(qABFOLGE.ToList(), true);
                var qWDECK = from m in mtemp.WDECK select m;
                DBMapper.MapWDECK(qWDECK.ToList(), true);
                var qWBDAT = from m in mtemp.WBDAT select m;
                DBMapper.MapWBDAT(qWBDAT.ToList(), true);
                var qWASTAMM = from m in mtemp.WASTAMM select m;
                DBMapper.MapWASTAMM(qWASTAMM.ToList(), true);
                var qWAFARBEN = from m in mtemp.WAFARBEN select m;
                DBMapper.MapWAFARBEN(qWAFARBEN.ToList(), true);
                var qVKPOS = from m in mtemp.VKPOS select m;
                DBMapper.MapVKPOS(qVKPOS.ToList(), true);
                var qVKKOPF = from m in mtemp.VKKOPF select m;
                DBMapper.MapVKKOPF(qVKKOPF.ToList(), true);
                var qVAFARBEN = from m in mtemp.VAFARBEN select m;
                DBMapper.MapVAFARBEN(qVAFARBEN.ToList(), true);
                var qVAART = from m in mtemp.VAART select m;
                DBMapper.MapVAART(qVAART.ToList(), true);
                var qLIEFDAT = from m in mtemp.LIEFDAT select m;
                DBMapper.MapLIEFDAT(qLIEFDAT.ToList(), true);
                var qKDSTAMM = from m in mtemp.KDSTAMM select m;
                DBMapper.MapKDSTAMM(qKDSTAMM.ToList(), true);
                var qGSDAT = from m in mtemp.GSDAT select m;
                DBMapper.MapGSDAT(qGSDAT.ToList(), true);
                var qGPBST = from m in mtemp.GPBST select m;
                DBMapper.MapGPBST(qGPBST.ToList(), true);
                var qGAAUF = from m in mtemp.GAAUF select m;
                DBMapper.MapGAAUF(qGAAUF.ToList(), true);
                var qABPOS = from m in mtemp.ABPOS select m;
                DBMapper.MapABPOS(qABPOS.ToList(), true);
                var qBAAUF = from m in mtemp.BAAUF select m;
                DBMapper.MapBAAUF(qBAAUF.ToList(), true);
                var qVAKOLL = from m in mtemp.VAKOLL select m;
                DBMapper.MapVAKOLL(qVAKOLL.ToList(), true);

            }
            catch (Exception ex)
            {

            }
            finally
            {
                mtemp.Dispose();
                GC.Collect();
            }
        }
        
        public Table<KDSTAMM> KDSTAMM
        {
            get
            {
                return this.GetTable<KDSTAMM>();
            }
        }
        public Table<VKPOS> VKPOS
        {
            get
            {
                return this.GetTable<VKPOS>();
            }
        }
        public Table<VAKOLL> VAKOLL
        {
            get
            {
                return this.GetTable<VAKOLL>();
            }
        }
        public Table<GSDAT> GSDAT
        {
            get
            {
                return this.GetTable<GSDAT>();
            }
        }
        public Table<LIEFDAT> LIEFDAT
        {
            get
            {
                return this.GetTable<LIEFDAT>();
            }
        }
        public Table<WASTAMM> WASTAMM
        {
            get
            {
                return this.GetTable<WASTAMM>();
            }
        }
        public Table<GPBST> GPBST
        {
            get
            {
                return this.GetTable<GPBST>();
            }
        }
        public Table<WBDAT> WBDAT
        {
            get
            {
                return this.GetTable<WBDAT>();
            }
        }
        public Table<VKPOS_EXT> VKPOS_EXT
        {
            get
            {
                return this.GetTable<VKPOS_EXT>();
            }
        }
        public Table<VKKOPF_EXT> VKKOPF_EXT
        {
            get
            {
                return this.GetTable<VKKOPF_EXT>();
            }
        }
        public Table<BAAUF> BAAUF
        {
            get
            {
                return this.GetTable<BAAUF>();
            }
        }
        public Table<ABFOLGE> ABFOLGE
        {
            get
            {
                return this.GetTable<ABFOLGE>();
            }
        }
        public Table<ABPOS> ABPOS
        {
            get
            {
                return this.GetTable<ABPOS>();
            }
        }
        public Table<ABAUFM> ABAUFM
        {
            get
            {
                return this.GetTable<ABAUFM>();
            }
        }
        public Table<WDECK> WDECK
        {
            get
            {
                return this.GetTable<WDECK>();
            }
        }
        public Table<VKKOPF> VKKOPF
        {
            get
            {
                return this.GetTable<VKKOPF>();
            }
        }
        public Table<VAART> VAART
        {
            get
            {
                return this.GetTable<VAART>();
            }
        }
        public Table<VAFARBEN> VAFARBEN
        {
            get
            {
                return this.GetTable<VAFARBEN>();
            }
        }
        public Table<GAAUF> GAAUF
        {
            get
            {
                return this.GetTable<GAAUF>();
            }
        }
        public Table<GSCOLOR> GSCOLOR
        {
            get
            {
                return this.GetTable<GSCOLOR>();
            }
        }
        public Table<WAFARBEN> WAFARBEN
        {
            get
            {
                return this.GetTable<WAFARBEN>();
            }
        }
        public Table<LOGINFO> LOGINFO
        {
            get
            {
                return this.GetTable<LOGINFO>();
            }
        }
        public Table<WPMENU> WPMENU
        {
            get
            {
                return this.GetTable<WPMENU>();
            }
        }

        public Table<SKYFILE> SKYFILE
        {
            get
            {
                return this.GetTable<SKYFILE>();
            }
        }
    }
}
